package com.changhai.diabetes.service.impl;

import java.util.List;

import com.changhai.diabetes.model.Bear;
import com.changhai.diabetes.model.BearForExport;
import com.changhai.diabetes.model.Patient;
import com.changhai.diabetes.service.BearService;
import com.changhai.diabetes.util.Constants;

/**
 * 鐢熻偛鍙�
 * 
 * @author Andy
 * 
 */
public class BearServiceImpl extends CommonServiceImpl implements BearService {
	public Bear searchByPatientId(Long patientid) {
		Object o = this.getObject(Constants.DS_CHANGHAI, "bear.getByPatientId", patientid);
		if (o != null && o instanceof Bear) {
			return (Bear) o;
		} else {
			Bear b = new Bear();
			b.setPatientid(patientid);
			return b;
		}
	}

	public void saveEditBear(Bear bear) {
		if (bear != null) {
			if (bear.getBearid() != null) {
				this.updateObject(Constants.DS_CHANGHAI, "bear.updateByPrimaryKey", bear);
			} else {
				Long bearid = this.saveNewBear(bear);
				if (bearid != null && bearid > 0) {
					bear.setBearid(bearid);
					this.updateObject(Constants.DS_CHANGHAI, "bear.updateByPrimaryKey", bear);
				}
			}
		}
	}

	public Long saveNewBear(Bear bear) {
		Integer id = 0;
		if (bear != null && bear.getPatientid() != null) {
			id = this.insertObjectID(Constants.DS_CHANGHAI, "bear.insert", bear);
		}
		return new Long(id);
	}
}
